C
C	MacInTalk in FORTRAN demo
C
C	Author: Craig Vaughan
C	
C	This program illustrates how to use the MacInTalk driver
C	from FORTRAN. Note that you must have the MacInTalk driver
C	either in the same folder as the application or in your
C	system folder for this application to work.
C
C	For licensing reasons, we do NOT supply the MacInTalk driver.
C	To obtain a copy check your local user group, bulletin board or
C	online service (CompuServe, America Online, GENIE, etc.).
C

C Load the Toolbox inlines
!!MP inlines.f
	program DemoSpeak
	implicit none
	
C Get the Types definitions
	include 'Types.f'
	
C Get the SpeechIntf (MacInTalk) definitions
	include 'SpeechIntf.f'
	
C Declare local variables
	INTEGER*2 SpchErr , theMode, thePitch, i
	STRING*255 ToSay
	
C Declare handles for MacInTalk
	RECORD /SpeechHandle/ theSpeech
	RECORD /Handle/ output

C Open the speech driver with no exceptions file
	SpchErr = SpeechOn(%ref(noExcpsFiles), %ref(theSpeech))
	IF (SpchErr <> 0) THEN		! There was a problem. Let the user know
		write (*,*) 'Unable to open Speech Driver. Mac OS Error:',SpchErr
		STOP					! Get outa here!
	 END IF

C Set up the mode and the pitch
	theMode = Natural			! Natural speech mode
	thePitch = 0				! Normal pitch
	CALL SpeechPitch(theSpeech, thePitch, theMode)

C Get a handle for translated speech. Initially 0 bytes. It will grow as required
	output = NewHandle(0)
	
C Set the input string to something other than quit
	toSay = ' '

C Keep asking for input until the user enters quit
	DO WHILE (toSay<>'quit'.and.toSay<>'QUIT')
		WRITE (*,*) 'What should I say? (Enter ÒquitÓ to exit)'
		READ (*,*) toSay
		IF (toSay<>'quit'.and.toSay<>'QUIT') THEN ! Are we quitting?
C If not then say it!
C Translate to phonemes
			SpchErr = Reader(theSpeech, %loc(toSay)+1,len(toSay), output)
C Speak the translated text
			SpchErr = MacinTalk(theSpeech, output)
		END IF
	END DO
	
C Close the speech driver
	CALL SpeechOff(theSpeech)

C Release the output handle
	CALL DisposHandle(output)

	END
